package com.augurit.common.syslog.web;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.syslog.service.ISysPropAuditLogService;
import com.augurit.common.syslog.web.form.SysPropAuditLogForm;
import com.augurit.common.util.ExtUtils;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "sys-prop-audit-log.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/common/syslog/sys-prop-audit-log.jsp"),
	@Result(name = SysPropAuditLogAction.PROJ_PROP_AUDIT_LOG_IFRAME, location = "/common/syslog/public/prop-audit-log-iframe.jsp")
})
public class SysPropAuditLogAction extends ExtCrudActionSupport<SysPropAuditLogForm>{

	private static final String PROJ_PROP_AUDIT_LOG_IFRAME = "prop-audit-log-iframe";
	
	@Autowired
	private ISysPropAuditLogService sysLogPropAuditService;

	private SysPropAuditLogForm form;
	private Long id;
	private Long[] ids;
	private Page<SysPropAuditLogForm> page = new Page<SysPropAuditLogForm>();


	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		ExtUtils.initPageFromExtGridParam(this.getRequest(), page);
		sysLogPropAuditService.search(page, form);
		this.extRenderGridJson(page);
		return null;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
		this.extRenderFormJson(form);
		return null;
	}

	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		sysLogPropAuditService.save(form);
		this.extRenderSuccess();
		return null;
	}

	/**
	 * 删除记录
	 */
	@Override
	public String delete() throws Exception {
		if(ids != null && ids.length > 0){
			for(Long id : ids){
				sysLogPropAuditService.delete(id);
			}
		}
		return null;
	}
	
	/**
	 * 分页显示某一个业务表的字段审计日志列表，按照修改人、修改时间排序
	 */
	public String getPropAuditLog()throws Exception{
		ExtUtils.initPageFromExtGridParam(this.getRequest(), page);
		sysLogPropAuditService.getLogListOrderByUpdatorAndTime(page, form.getEntity(), form.getEntityId(), null);
		this.extRenderGridJson(page);
		return null;
	}
	
	/**
	 * 显示某一个业务表的字段审计日志，按照修改人、修改时间排序
	 */
	public String showPropAuditLog()throws Exception{
		return PROJ_PROP_AUDIT_LOG_IFRAME;
	}
	
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = sysLogPropAuditService.get(id);
		}
		else
			form = new SysPropAuditLogForm();
	}
	

	public SysPropAuditLogForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}

	public SysPropAuditLogForm getForm() {
		return form;
	}

	public void setForm(SysPropAuditLogForm form) {
		this.form = form;
	}
}
